package com.mh.service;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mh.dao.AppRoleDAO;
import com.mh.domain.AppRole;
import com.mh.domain.Customer;

/**
 * Spring service that handles CRUD requests for AppRole entities
 * 
 */

@Service("AppRoleService")
@Transactional
public class AppRoleServiceImpl implements AppRoleService {

	/**
	 * DAO injected by Spring that manages AppRole entities
	 * 
	 */
	@Autowired
	private AppRoleDAO appRoleDAO;

	/**
	 * Instantiates a new AppRoleServiceImpl.
	 *
	 */
	public AppRoleServiceImpl() {
	}

	/**
	 * Load an existing AppRole entity
	 * 
	 */
	@Transactional
	public Set<AppRole> loadAppRoles() {
		return appRoleDAO.findAllAppRoles();
	}

	/**
	 * Return all AppRole entity
	 * 
	 */
	@Transactional
	public List<AppRole> findAllAppRoles(Integer startResult, Integer maxRows) {
		return new java.util.ArrayList<AppRole>(appRoleDAO.findAllAppRoles(startResult, maxRows));
	}

	/**
	 * Delete an existing AppRole entity
	 * 
	 */
	@Transactional
	public void deleteAppRole(AppRole approle) {
		appRoleDAO.remove(approle);
		appRoleDAO.flush();
	}

	/**
	 * Save an existing AppRole entity
	 * 
	 */
	@Transactional
	public void saveAppRole(AppRole approle) {
		AppRole existingAppRole = appRoleDAO.findAppRoleByPrimaryKey(approle.getId());

		if (existingAppRole != null) {
			if (existingAppRole != approle) {
				existingAppRole.setId(approle.getId());
				existingAppRole.setApplication(approle.getApplication());
				existingAppRole.setRoleName(approle.getRoleName());
				existingAppRole.setDescription(approle.getDescription());
			}
			approle = appRoleDAO.store(existingAppRole);
		} else {
			approle = appRoleDAO.store(approle);
		}
		appRoleDAO.flush();
	}

	/**
	 */
	@Transactional
	public AppRole findAppRoleByPrimaryKey(Integer id) {
		return appRoleDAO.findAppRoleByPrimaryKey(id);
	}

	/**
	 * Return a count of all AppRole entity
	 * 
	 */
	@Transactional
	public Integer countAppRoles() {
		return ((Long) appRoleDAO.createQuerySingleResult("select count(o) from AppRole o").getSingleResult()).intValue();
	}

	public List<AppRole> findAllAppRole(AppRole approle, Integer startResult,
			Integer maxRows) {
		return appRoleDAO.findAllAppRoles(approle, startResult, maxRows);
	}
	
	@Transactional
	public Set<AppRole>  findAppRoles(AppRole appRole) {
		return appRoleDAO.findAppRoles(appRole);
	}



}
